import { IHttp } from '@utils/http';
import { uniqueId } from 'lodash-es';
import { defineStore } from 'pinia';
import { inject } from 'vue';

class Tmpl {
  static create(id: number | string) {
    const store_id = `/ur-prefix/${id}`;

    const use_store = defineStore(store_id, () => {
      const api = inject<IHttp>('api');

      function $reset(): void {}

      async function load(): Promise<any> {
        if (!api) {
          throw new Error('Http module not found');
        }

        const api_endpoint = '/v1/driver/service-provider/addresses';
        const { data } = await api.get<unknown>(api_endpoint, {});

        console.log(data);
      }

      return {
        /** states */

        /** views */

        /** actions */
        $reset,
        load,
      };
    });

    return use_store();
  }
}

function useTmpl(id: number | string = uniqueId()) {
  return Tmpl.create(id);
}

export { useTmpl };
